<template>
  <div class="myDropdownList">
    <div class="slot">
      <div
        class="iconfont icon"
        @click="showDropDownList"
        @mouseleave="onMouseleave"
      >
        &#xe6de;
      </div>
    </div>
    <transition name="fade">
      <div
        v-show="show"
        class="drop-down-list"
        @mouseover="onMouseover"
        @mouseleave="show = false"
      >
        <div
          v-for="(item, key) in list"
          :key="key"
          class="list-item"
          @click="handleClickItem(key)"
        >
          <!-- 复选框 -->
          <div class="square">
            <div v-if="item.show" class="iconfont mark">&#xe604;</div>
          </div>
          <!-- 文字 -->
          <div class="text">{{ item.text }}</div>
        </div>
      </div>
    </transition>
  </div>
</template>

<script>
export default {
  components: {},
  props: {
    list: {
      default: () => {},
    },
  },
  data() {
    return {
      show: false,
      timer: null,
    };
  },
  mounted() {},
  methods: {
    showDropDownList() {
      this.show = !this.show;
    },
    onMouseleave() {
      this.timer = setTimeout(() => {
        this.show = false;
      }, 500);
    },
    onMouseover() {
      clearInterval(this.timer);
    },
    handleClickItem(key) {
      this.$emit("change", key);
    },
  },
};
</script>

<style lang="less" scoped>
.myDropdownList {
  position: relative;
}
.drop-down-list {
  position: absolute;
  z-index: 100;
  top: 30px;
  left: -100px;
  width: 172px;
  max-height: 270px;
  padding: 0 32px;
  box-sizing: border-box;
  border-radius: 15px;
  background-color: #f4f7fc;
  overflow: auto;
  &::-webkit-scrollbar {
    width: 0px;
    height: 0px;
  }
  .list-item {
    display: flex;
    align-items: center;
    width: 100%;
    height: 45px;
    line-height: 45px;
    cursor: pointer;
    user-select: none;
    .square {
      position: relative;
      width: 12px;
      height: 12px;
      border: 2px solid #387CF7;
      border-radius: 5px;
      margin-right: 10px;
      .mark {
        position: absolute;
        left: -1px;
        top: -18px;
        color: #387CF7;
        font-size: 18px;
      }
    }
    .text {
      color: #387CF7;
      font-size: 14px;
    }
  }
}
.icon {
  font-size: 17px;
  color: rgba(212, 212, 212);
  cursor: pointer;
  user-select: none;
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.2s;
}
.fade-enter,
.fade-leave-active {
  opacity: 0;
}
</style>